class Ctrl {
    constructor(list, alarmSrv, ctgNotification, ctgColor) {
        "ngInject";

        this._alarmSrv = alarmSrv;
        this._notification = ctgNotification;
        this._color = ctgColor;

        this.page = {
            perPage: 10,
            currentPage: 1,
            totalItems: 0
        };
        if (list) {
            this.table = list.list;
            this.page.totalItems = list.total;
            angular.forEach(this.table, elem=> {
                elem.bg = {'background-color': this._color[elem.id % this._color.length]};
            });
        } else this.table = [];
    }

    getList() {
        this._alarmSrv.getNotificationList({pageNum: this.page.currentPage}).then(data=> {
            this.table = data.list;
            this.page.totalItems = data.total;
            angular.forEach(this.table, elem=> {
                elem.bg = {'background-color': this._color[elem.id % this._color.length]};
            });
        })
    }

    markNotification(elem){
        elem.marked = true;
        this._alarmSrv.editNotice(elem.id).then(()=>{
            this.getList();
        }).catch(()=>{
            this._notification.error("网络连接失败.")
        })
    }
}
export default Ctrl